UI (Front end)
Server (Back end)
Run the app
R files
Single file (app.R)
Multiple file (ui.R & server.R)
UI (Front end)
Define the layout of the app’s user interface.
Create components for user input and output.
UI (Front end)
Define the layout of the app’s user interface.
Create components for user input and output.
Server (Back end)
Makes user input available to use in R scripts
Process data
Send outputs back to UI
library(shiny)
ui <- fluidPage(
titlePanel("Old Faithful Geyser Data"),
sidebarLayout(
sidebarPanel(
sliderInput(inputID = "bins",
label = "Number of bins:",
min = 1, max = 50, value = 30
)
),
mainPanel(
plotOutput(outputID = "distPlot")
)
)
)
server <- function(input, output) {
output$distPlot <- renderPlot({
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)
hist(x, breaks = bins, col = 'darkgray', border = 'white',
xlab = 'Waiting time to next eruption (in mins)',
main = 'Histogram of waiting times')
})
}UI (Front end)
Define the layout of the app’s user interface.
Create components for user input and output.
Server (Back end)
Makes user input available to use in R scripts
Process data
Send outputs back to UI
Run the app
library(shiny)
ui <- fluidPage(
titlePanel("Old Faithful Geyser Data"),
sidebarLayout(
sidebarPanel(
sliderInput(inputID = "bins",
label = "Number of bins:",
min = 1, max = 50, value = 30
)
),
mainPanel(
plotOutput(outputID = "distPlot")
)
)
)
server <- function(input, output) {
output$distPlot <- renderPlot({
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)
hist(x, breaks = bins, col = 'darkgray', border = 'white',
xlab = 'Waiting time to next eruption (in mins)',
main = 'Histogram of waiting times')
})
}
shinyApp(ui = ui, server = server)Input and output objects
library(shiny)
ui <- fluidPage(
titlePanel("Old Faithful Geyser Data"),
sidebarLayout(
sidebarPanel(
sliderInput(inputID = "bins",
label = "Number of bins:",
min = 1, max = 50, value = 30
)
),
mainPanel(
plotOutput(outputID = "distPlot")
)
)
)
server <- function(input, output) {
output$distPlot <- renderPlot({
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)
hist(x, breaks = bins, col = 'darkgray', border = 'white',
xlab = 'Waiting time to next eruption (in mins)',
main = 'Histogram of waiting times')
})
}
shinyApp(ui = ui, server = server)Input and output objects
library(shiny)
ui <- fluidPage(
titlePanel("Old Faithful Geyser Data"),
sidebarLayout(
sidebarPanel(
sliderInput(inputID = "bins",
label = "Number of bins:",
min = 1, max = 50, value = 30
)
),
mainPanel(
plotOutput(outputID = "distPlot")
)
)
)
server <- function(input, output) {
output$distPlot <- renderPlot({
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)
hist(x, breaks = bins, col = 'darkgray', border = 'white',
xlab = 'Waiting time to next eruption (in mins)',
main = 'Histogram of waiting times')
})
}
shinyApp(ui = ui, server = server)Page functions
fluidPage()
fixedPage()
fillPage()
navbarPage()
Layout functions
Layout packages:
Custom theming
Further reading: https://www.appsilon.com/post/shiny-application-layouts
actionButton()
checkboxInput()
dateInput()
fileInput()
numericInput()
radioButtons()
selectInput()
sliderInput()
textInput()
| Output | Render |
|---|---|
| textOutput() | renderText() |
| verbatimTextOutput() | renderPrint() |
| tableOutput() | renderTable() |
| plotOutput() | renderPlot() |
| uiOutput() | renderUI() |
| imageOutput() | renderImage() |
Widget packages:
Output interactivity
Local project
Run from Github
Shinyapps.io
Private server or cloud server
shiny server
shinyProxy
Wasm – webR
Official apps
Shiny extensions
https://github.com/nanxstats/awesome-shiny-extensions
Course
https://shiny.posit.co/r/getstarted/shiny-basics/lesson1/index.html
Video
https://laderast.github.io/edu/2021-03-20-a-gradual-introduction-to-shiny/
Books
https://mastering-shiny.org/index.html
https://engineering-shiny.org/
https://unleash-shiny.rinterface.com/
https://book.javascript-for-r.com/